print('字面值')
s = 'university'
print(s)
print(isinstance(s, str))
assert type(s) is str
print('f-string')
x = 'Tom'
s = f'name: {x}'
print(s)
pi = 3.1415926
print(f"圆周率约等于 {pi:.2f}")  # 输出：圆周率约等于 3.14
text = "hello"
print(f"{text:>10}")  # 右对齐，输出：     hello
from datetime import datetime
today = datetime.now()
print(f"今天是 {today:%Y-%m-%d}")  # 输出：今天是 2025-05-28
s = 'a\tb'
print(s)
print('happiness', s)
print('tab', s)
k= 'aaaa\tb'
print('tab', k)
g = 'aaa\nbbbb'
print('newline', g)
c = 'a\\b'
print(c)
path = r"C:\Users\Desktop\file.txt" 
print(path)
q = r"换行符：\n，制表符：\t"
print(q)  # 输出：换行符：\n，制表符：\t
xm = '''happy
samrt
    gentle
kindness
'''
print(xm)

s = str([5, 8, 2])
print(s)
s = str(1.1 + 2.2)
print(s)
s = '='
s = s * 20
print(s)
s = 'abc'
s = s *10
print(s)
s = "Hello"
print(s[0])   # 输出：H（第一个元素）
print(s[2])   # 输出：l（第三个元素）
print(s[-1])  # 输出：o（最后一个元素）
print(s[-3])  # 输出：l（倒数第三个元素）
s = 'hello'
u = s.upper()
print(s)
print(u)
s1 = "Hello"
s2 = " World"
s3 = s1 + s2  # 拼接字符串
print(s3)     # 输出：Hello World
s = "abc" * 3  # 重复3次
print(s)       # 输出：abcabcabc

s = "Hi" * 0   # 重复0次得到空字符串
print(s)       # 输出：''
s = 'aaaa'
print("a" > "A")
print("Z" > "a")
print("apple" > "Apple")
print("100" < "2")
print("abc" > "ab")
print("apple" < "apply")

s = "book"
print(s[1:3])
s = "book"
for char in s:
    print(char)

s = "book"
it = iter(s)  # 创建字符串迭代器

print(next(it))  # 输出: 'b' (第一个字符)
print(next(it))  # 输出: 'o' (第二个字符)
print(next(it))  # 输出: 'o' (第三个字符)
print(next(it))  # 输出: 'k' (第四个字符)

# 用逗号连接
fruits = ["apple", "banana", "cherry"]
print(",".join(fruits))  
# 用连字符连接
numbers = ["1", "2", "3"]
print("-".join(numbers))  
# 用空字符串连接（无缝拼接）
letters = ["P", "y", "t", "h", "o", "n"]
print("".join(letters)) 

text = "你好，世界！Hello, world!"
byte_data = text.encode("utf-8")
print(byte_data)

a = 2023
b = 2024
print(a + b)

pi = 3.14159
temperature = 36.6
# 浮点数运算
circle_area = pi * 5 ** 2  # πr²
print(f"半径为5的圆面积: {circle_area:.2f}")

nice = True
bad = False
print(nice and bad)
print(nice or bad)
print(not nice)

age = 18
can_vote = age >= 18
print(f"可以投票: {can_vote}")

# 创建列表
fruits = ["苹果", "香蕉", "橙子"]
numbers = [1, 2, 3, 4, 5]

# 访问元素
print(fruits[0])     
print(numbers[-1])   
# 修改列表
fruits.append("葡萄")  
print(fruits)         
numbers[2] = 99      
print(numbers)    
# 列表切片
print(numbers[1:3])  

# 创建字典
person = {
    "name": "张三",
    "age": 30,
    "is_student": False
}

# 访问值
print(person["name"]) 
print(person.get("age")) 

# 添加/修改值
person["job"] = "工程师" 
person["age"] = 31      

# 遍历字典
print("个人信息:")
for key, value in person.items():
    print(f"{key}: {value}")

# 创建集合
colors = {"红", "绿", "蓝"}
numbers = set([1, 2, 2, 3, 3, 3])  

print(numbers) 

# 集合运算
primary = {"红", "绿", "蓝"}
secondary = {"绿", "紫", "橙"}

print(primary & secondary)  
print(primary | secondary)  
print(primary - secondary)  

# 添加/删除元素
colors.add("黄")
print(colors)  

colors.remove("绿")
print(colors)  

from datetime import datetime, timedelta, date
now = datetime.now()
print(f"当前时间: {now}")  
# 获取当前日期
today = date.today()
print(f"今天日期: {today}")  
# 创建特定日期
birthday = date(2002, 7, 21)
print(f"生日: {birthday}")  

# 计算未来日期
next_week = today + timedelta(days=7)
print(f"一周后: {next_week}")  

# 计算时间差
new_year = date(2026, 1, 1)
days_left = (new_year - today).days
print(f"距离2024年还有: {days_left} 天")

# 日期 → 字符串
formatted = now.strftime("%Y-%m-%d %H:%M:%S")
print(f"格式化时间: {formatted}") 

# 字符串 → 日期
date_str = "2025-12-25"
christmas = datetime.strptime(date_str, "%Y-%m-%d")
print(f"圣诞节是: {christmas.date()}")  